package com.easyaop.test.core.intercept;

import net.bytebuddy.implementation.bind.annotation.AllArguments;
import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;

/**
 * @author lipan
 * @since 2025-01-20
 */
public class MethodIntercept {
    @RuntimeType
    public Object intercept(
            //表示被拦截的目标对象，只有拦截实力方法时可用
            // @This Object targetObject,
            //表示被拦截的目标方法，只有拦截实例方法，和静态方法时可用
            @Origin Method targetMethod,
            //目标方法的参数
            @AllArguments Object[] args,
            @SuperCall Callable<?> supCall) {
        System.out.println("start...");
        Object call = null;
        try {
            call = supCall.call();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        System.out.println("start...");
        return call;
    }
}
